<?php

require_once( 'AbstractDatasource.php' );

class TestDatasource extends AbstractDatasource {

	var $aTestTables;
	var $aTestPrimaryKeys;
	var $aTestKeys;
	
	function TestDatasource() {
		
		$this->AbstractDatasource();
		$this->iLastDdl     = time();

		$this->aTestTables['STUDENT']        = array( array( 'NAME' => 'COLLEGE_ID'     , 'DATATYPE' => 'NUMBER'   )
													, array( 'NAME' => 'ID'             , 'DATATYPE' => 'NUMBER'   )
													, array( 'NAME' => 'FIRST_NAME'     , 'DATATYPE' => 'VARCHAR2' )
													, array( 'NAME' => 'SURNAME'        , 'DATATYPE' => 'VARCHAR2' )
													, array( 'NAME' => 'KNOWN_AS'       , 'DATATYPE' => 'VARCHAR2' )
													, array( 'NAME' => 'REGISTRATION_NO', 'DATATYPE' => 'VARCHAR2' )
													);
		$this->aTestPrimaryKeys['STUDENT']    = array( 'NAME'    => 'STUDENT_PK'
													, 'COLUMNS' => array( 'COLLEGE_ID', 'ID' ) );


		$this->aTestTables['ACTIVITY']       = array( array( 'NAME' => 'ID'             , 'DATATYPE' => 'NUMBER'   )
													, array( 'NAME' => 'NAME'           , 'DATATYPE' => 'VARCHAR2' )
													, array( 'NAME' => 'DESCRIPTION'    , 'DATATYPE' => 'VARCHAR2' )
													);
		$this->aTestPrimaryKeys['ACTIVITY']   = array( 'NAME'    => 'ACTIVITY_PK'
													 , 'COLUMNS' => array( 'ID' ) );


		$this->aTestTables['SOCIETY']        = array( array( 'NAME' => 'ID'                          , 'DATATYPE' => 'NUMBER'   )
													, array( 'NAME' => 'NAME'                        , 'DATATYPE' => 'VARCHAR2' )
													, array( 'NAME' => 'STUDENT_COLLEGE_ID_PRESIDENT', 'DATATYPE' => 'NUMBER' )
													, array( 'NAME' => 'STUDENT_ID_PRESIDENT'        , 'DATATYPE' => 'NUMBER' )
													, array( 'NAME' => 'STUDENT_COLLEGE_ID_SECRETARY', 'DATATYPE' => 'NUMBER' )
													, array( 'NAME' => 'STUDENT_ID_SECRETARY'        , 'DATATYPE' => 'NUMBER' )
													);

		$this->aTestPrimaryKeys['SOCIETY']    = array( 'NAME'    => 'SOCIETY_PK'
													, 'COLUMNS' => array( 'ID' ) );


		$this->aTestTables['SOCIETY_MEMBERSHIP'] = array( array( 'NAME' => 'SOCIETY_ID'        , 'DATATYPE' => 'NUMBER' )
														, array( 'NAME' => 'STUDENT_COLLEGE_ID', 'DATATYPE' => 'NUMBER' )
													    , array( 'NAME' => 'STUDENT_ID'        , 'DATATYPE' => 'NUMBER' )
													    );
		$this->aTestPrimaryKeys['SOCIETY_MEMBERSHIP']  = array( 'NAME'    => 'SOCIETY_MEMBERSHIP_PK'
															 , 'COLUMNS' => array( 'SOCIETY_ID', 'STUDENT_ID' ) );


		$this->aTestTables['SOCIETY_ACTIVITY']   = array( array( 'NAME' => 'SOCIETY_ID' , 'DATATYPE' => 'NUMBER' )
												        , array( 'NAME' => 'ACTIVITY_ID', 'DATATYPE' => 'NUMBER' )
													    );
		$this->aTestPrimaryKeys['SOCIETY_ACTIVITY']    = array( 'NAME'    => 'SOCIETY_ACTIVITY_PK'
															, 'COLUMNS' => array( 'SOCIETY_ID', 'ACTIVITY_ID' ) );

		$this->aTestTables['COLLEGE']       	= array( array( 'NAME' => 'ID'            , 'DATATYPE' => 'NUMBER'   )
													   , array( 'NAME' => 'NAME'          , 'DATATYPE' => 'VARCHAR2' )
													   );
		$this->aTestPrimaryKeys['COLLEGE']    = array( 'NAME'    => 'COLLEGE_PK'
													, 'COLUMNS' => array( 'ID' ) );

		$this->aTestKeys = array( array( 'NAME' => 'SOCIETY_STUDENT_PRESIDENT_FK' , 'FROM_TABLE' => 'SOCIETY'           , 'FROM_COLUMNS' => array( 'STUDENT_COLLEGE_ID_PRESIDENT', 'STUDENT_ID_PRESIDENT' ) , 'TO_TABLE' => 'STUDENT' , 'MANDATORY' => '0' )
								, array( 'NAME' => 'SOCIETY_STUDENT_SECRETARY_FK' , 'FROM_TABLE' => 'SOCIETY'           , 'FROM_COLUMNS' => array( 'STUDENT_COLLEGE_ID_SECRETARY', 'STUDENT_ID_SECRETARY' ) , 'TO_TABLE' => 'STUDENT' , 'MANDATORY' => '0' )
								, array( 'NAME' => 'SOCIETY_ACTIVITY_SOCIETY_FK'  , 'FROM_TABLE' => 'SOCIETY_ACTIVITY'  , 'FROM_COLUMNS' => array( 'SOCIETY_ID' )                                           , 'TO_TABLE' => 'SOCIETY' , 'MANDATORY' => '1' )
								, array( 'NAME' => 'SOCIETY_ACTIVITY_ACTIVITY_FK' , 'FROM_TABLE' => 'SOCIETY_ACTIVITY'  , 'FROM_COLUMNS' => array( 'ACTIVITY_ID' )                                          , 'TO_TABLE' => 'ACTIVITY', 'MANDATORY' => '1' )
								, array( 'NAME' => 'SOCIETY_MEMBERSHIP_SOCIETY_FK', 'FROM_TABLE' => 'SOCIETY_MEMBERSHIP', 'FROM_COLUMNS' => array( 'SOCIETY_ID' )                                           , 'TO_TABLE' => 'SOCIETY' , 'MANDATORY' => '1' )
								, array( 'NAME' => 'SOCIETY_MEMBERSHIP_STUDENT_FK', 'FROM_TABLE' => 'SOCIETY_MEMBERSHIP', 'FROM_COLUMNS' => array( 'STUDENT_COLLEGE_ID', 'STUDENT_ID' )                     , 'TO_TABLE' => 'STUDENT' , 'MANDATORY' => '1' )
								, array( 'NAME' => 'SOCIETY_MEMBERSHIP_COLLEGE_FK', 'FROM_TABLE' => 'SOCIETY_MEMBERSHIP', 'FROM_COLUMNS' => array( 'STUDENT_COLLEGE_ID')                                    , 'TO_TABLE' => 'COLLEGE' , 'MANDATORY' => '1' )
								, array( 'NAME' => 'STUDENT_COLLEGE_FK'           , 'FROM_TABLE' => 'STUDENT'           , 'FROM_COLUMNS' => array( 'COLLEGE_ID' )                                           , 'TO_TABLE' => 'COLLEGE' , 'MANDATORY' => '1' )
								, array( 'NAME' => 'SOCIETY_COLLEGE_PRESIDENT_FK' , 'FROM_TABLE' => 'SOCIETY'           , 'FROM_COLUMNS' => array( 'STUDENT_COLLEGE_ID_PRESIDENT' )                         , 'TO_TABLE' => 'COLLEGE' , 'MANDATORY' => '0' )
								, array( 'NAME' => 'SOCIETY_COLLEGE_SECRETARY_FK' , 'FROM_TABLE' => 'SOCIETY'           , 'FROM_COLUMNS' => array( 'STUDENT_COLLEGE_ID_SECRETARY' )                         , 'TO_TABLE' => 'COLLEGE' , 'MANDATORY' => '0' )
								);

	}
	
	function GetTableList() {
		return array_keys( $this->aTestTables );
	}

	function GetColumnList( $sTableName ) {
		return $this->aTestTables[ $sTableName ];
	}
	
	function GetForeignKeys( $sTableName ) {
		$aReturnKeys = array();
		foreach ( $this->aTestKeys as $aThisKey ) {
			if ( $aThisKey['FROM_TABLE'] == $sTableName || $aThisKey['TO_TABLE'] == $sTableName ) {
				$aReturnKeys[] = $aThisKey;	
			}
		}
		return $aReturnKeys;
	}
	
	function GetPrimaryKey( $sTableName ) {
		return $this->aTestPrimaryKeys[ $sTableName ];
	}
	
	function GetDatasourceId() {
		return 'TestDatasource';	
	}

}

?>
